package org.akomantoso.core.data;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.akomantoso.core.io.Externalizable;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.visitor.AKVisitor;

public abstract class MixedContentWithCoreReqReq<T extends MixedItem> extends CoreReqReqImpl implements Mixed<T>, Externalizable {

	private final List<T> _data = new ArrayList<T>();

	/**
	 * @see org.akomantoso.core.data.Mixed#getData()
	 */
	public List<T> getData() {
		return _data;
	}

	/**
	 * @see org.akomantoso.core.data.Mixed#addData(org.akomantoso.core.data.MixedItem)
	 */
	public void addData(T data) {
		_data.add(data);
	}
	
	/**
	 * @see org.akomantoso.core.io.Externalizable#writeExternal(org.akomantoso.core.io.Output)
	 */
	public <E extends Output> void writeExternal(E out) throws IOException {
		super.writeExternal(out);
		for (int i = 0, n = _data.size(); i < n; i++) {
			_data.get(i).writeExternal(out);
		}
	}

	protected final void internalAccept(AKVisitor visitor) {
		for (int i = 0, n = _data.size(); i < n; i++) {
			_data.get(i).accept(visitor);
		}
	}

}